#!/bin/bash
cd /
image=$1

ucode_level=`rpm -qa | grep "IBMhsc\.ucode\-mgr\-"`
# rpm --erase $ucode_level

SNM_level=`rpm -qa | grep "IBMhsc\.SNM\-"`
# rpm --erase $SNM_level

SNM_GUI_level=`rpm -qa | grep "IBMhsc\.SNM_GUI\-"`
# rpm --erase $SNM_GUI_level

# rpm --install $image/IBMhsc.ucode-mgr-1.1.1.1-1.i386.rpm
# rpm --install $image/IBMhsc.SNM-1.1.1.1-1.i386.rpm
# rpm --install $image/IBMhsc.SNM_GUI-1.1.1.1-1.i386.rpm

rpm -U --force $image/IBMhsc.ucode-mgr-1.2.2.0-1.i386.rpm
rpm -U --force $image/IBMhsc.SNM-1.2.2.0-1.i386.rpm
rpm -U --force $image/IBMhsc.SNM_GUI-1.2.2.0-1.i386.rpm

# To replace hardware server, need to mess with /etc/inittab
# First remove the entry from /etc/inittab
/bin/sed -e '/^hsv:/d' /etc/inittab > /tmp/hsc_tmp_inittab

# Now add the commented entry and mv the file back
echo "#hsv:2345:respawn:/opt/hsc/bin/startHDWR_SVR 1>/dev/null 2>&1" >> /tmp/hsc_tmp_inittab
mv /tmp/hsc_tmp_inittab /etc/inittab

# Cause the file to be re-examined
/sbin/telinit q

# Now copy over the new hdwr_svr executable after saving the old
mv /opt/hsc/bin/hdwr_svr /opt/hsc/bin/hdwr_svr.orig_$$
cp -p $image/hdwr_svr /opt/hsc/bin/hdwr_svr
chmod 555 /opt/hsc/bin/hdwr_svr

# Now fix up /etc/inittab
# First remove the entry from /etc/inittab
/bin/sed -e '/^#hsv:/d' /etc/inittab > /tmp/hsc_tmp_inittab

# Now add the uncommented entry and mv the file back
echo "hsv:2345:respawn:/opt/hsc/bin/startHDWR_SVR 1>/dev/null 2>&1" >> /tmp/hsc_tmp_inittab
mv /tmp/hsc_tmp_inittab /etc/inittab

# Do not need to run telinit q again because a reboot will follow this install

exit 0
